package com.enjoyor.health.HGPT.web.rest;

import com.alibaba.fastjson2.JSONArray;
import com.enjoyor.health.HGPT.core.dto.WatchDataDto;
import com.enjoyor.health.HGPT.core.entity.WatchData;
import com.enjoyor.health.HGPT.service.BizWatchService;
import com.enjoyor.health.HGPT.web.CodeEnum;
import com.enjoyor.health.HGPT.web.RetResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author Zhu Min
 * @date 2023/12/13 14:21
 */
@Api(value = "手表", tags = {"手表"})
@RestController
public class WatchController {

    @Autowired
    private BizWatchService bizWatchService;

    @PostMapping(value = "/aiHealthReport/saveWatchData")
    public RetResult saveWatchData(@RequestBody WatchDataDto data){
        if (StringUtils.isBlank(data.getOpenId())&& StringUtils.isBlank(data.getUserId())) {
            return new RetResult(CodeEnum.NO_USER_INFO);
        }
        if (StringUtils.isBlank(data.getData() )){
            return new RetResult(CodeEnum.DATA_NULL);
        }
        return new RetResult(bizWatchService.save(data));
    }

    @RequestMapping(value = "/aiHealthReport/getWatchData", method = { RequestMethod.GET, RequestMethod.POST })
    public RetResult getWatchData(WatchDataDto watchDataDto){
        return new RetResult().setResult(bizWatchService.getList(watchDataDto.getType(), watchDataDto.getOpenId(), watchDataDto.getUserId(), watchDataDto.getDeviceId()));
    }

    @ApiOperation(value = "常见问题接口")
    @RequestMapping(value = "/aiHealthReport/faq", method = { RequestMethod.GET, RequestMethod.POST })
    public RetResult getFaq(){
        return new RetResult().setResult(bizWatchService.getCommonInfoByType("FAQ"));
    }
}
